package example.androbot.plugin;

import android.app.IntentService;
import android.content.Intent;

import com.unicorntoast.android.androbot_libs.utils.AndrobotUtils;

public class PluginService extends IntentService {

	public PluginService() {
		super("my example plugin");
	}

	@Override
	protected void onHandleIntent(Intent intent) {
		
//		Debug.waitForDebugger();

		String secret = getSharedPreferences("androbot", 0)
				.getString("secret", null);
			
		// not yet registered?
		if( secret==null )
			return;

		if( !secret.equals(AndrobotUtils.secret(intent)) )
			return; // malicious !?
		
		AndrobotUtils.sendMessage(this,secret, 
			String.format("got command: '%s'",AndrobotUtils.command(intent))
		);
		
	}

}
